﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using TinyLib.Input;
using TinyLib.Sprite;
using TinyLib.Entity;

namespace GodBuilderIdea
{
    public class EnvTile : Entity
    {
        public enum EnvironmentType
        {
            GRASS,
            FOREST,
            DESERT,
            WATER,
            SNOW,
            MOUNTAIN,
            SWAMP,
            LAVA,
            NEXT,
            DEFAULT,
            SIZE
        };

        public EnvironmentType m_type;
        public bool m_changed_type = false;

        public bool left = false;
        public bool right = false;
        public bool top = false;
        public bool bottom = false;

        public EnvTile(Game game, SpriteBatch sprite_batch)
            : base(game, sprite_batch)
        {
            m_type = EnvironmentType.DEFAULT;
            texture2D = Game.Content.Load<Texture2D>("images/default_tile");
            Rectangle = new Rectangle((int)position.X, (int)position.Y, texture2D.Width, texture2D.Height);
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public void ChangeType(EnvironmentType type)
        {
            m_type = type;
            m_changed_type = true;
        }

        public override void Update(GameTime gameTime)
        {
            Rectangle = new Rectangle((int)position.X, (int)position.Y, texture2D.Width, texture2D.Height);
            base.Update(gameTime);

            if (m_changed_type)
            {
                if (m_type == EnvironmentType.GRASS)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/grass_tile");
                }
                else if (m_type == EnvironmentType.FOREST)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/forest_tile");
                }
                else if (m_type == EnvironmentType.DESERT)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/desert_tile");
                }
                else if (m_type == EnvironmentType.WATER)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/water_tile");
                }
                else if (m_type == EnvironmentType.SNOW)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/snow_tile");
                }
                else if (m_type == EnvironmentType.MOUNTAIN)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/mountain_tile");
                }
                else if (m_type == EnvironmentType.SWAMP)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/swamp_tile");
                }
                else if (m_type == EnvironmentType.NEXT)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/done_btn");
                }
                else if (m_type == EnvironmentType.LAVA)
                {
                    texture2D = Game.Content.Load<Texture2D>("images/lava_tile");
                }


                m_changed_type = false;
            }
        }

        public override void Draw(GameTime gameTime)
        {
            //base.Draw(gameTime);
            Spritebatch.Draw(texture2D, new Rectangle((int)position.X, (int)position.Y, (int)texture2D.Width, (int)texture2D.Height), Color.White);
        }
    }
}
